<template>
    <div>
        <h3>当前求和的值为:{{sum}}</h3>
        <h3>当前求和放大10倍的值为:{{bigSum}}</h3>
        <h3>学校是:{{school}},地址是:{{addr}}</h3>

        <select v-model.number="n">
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
        </select>
        <button @click="increment(n)">+</button>
        <button @click="decrement(n)">-</button>
        <button @click="incrementOdd(n)">当前求和为奇数再加</button>
        <button @click="incrementWait(n)">等一等再加</button>
    </div>
</template>

<script>
    import {mapState,mapGetters,mapMutations,mapActions} from 'vuex'

    export default {
        name:'Count',
       data() {
           return {
               n:1
           }
       },
       computed:{
           // 借助 mapstate 生成计算属性
            //...mapState({sum:'sum',school:'school',addr:'addr'}),
            ...mapState(['sum','school','addr']),
            ...mapGetters(['bigSum'])
       },

       methods: {
           /* increment(){
                this.$store.commit('ADD', this.n);
           },
           decrement(){
               this.$store.commit('DECREMENT', this.n);
           }, */
           ...mapMutations({increment:'ADD',decrement:'DECREMENT'}),
            //  **********************************************
           // 奇数再加
           /* incrementOdd(){
               this.$store.dispatch('incrementOdd', this.n);
           },
           incrementWait(){
               this.$store.dispatch('incrementWait', this.n);
           }, */
            ...mapActions(['incrementOdd','incrementWait']),

       },
    
    }
</script>

<style>
    button{
        margin-left: 10px;
    }
</style>